﻿using AuApmt.Models.DbModels;
using AuApmt.Models.Dto;
using AuApmt.Repos.Schedules;
using AuApmt.Services.App.ActionFilters;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace AuApmt.Controllers.Schedules
{
    [Authorize]
    public class SubjectController(
        SubjectRepo subjectRepo
        ) : Controller
    {
        public IActionResult Index()
        {
            var list = subjectRepo.IndexSubject();
            return this.ApiResp(list);
        }

        [UserTypeRestricted(UserType.Admin)]
        public IActionResult Create([FromBody]SubjectDto subject)
        {
            var success = subjectRepo.CreateSubject(subject, out var errmsg);
            return this.ApiResp(success, errmsg);
        }

        [UserTypeRestricted(UserType.Admin)]
        public IActionResult Update([FromBody]SubjectDto subject)
        {
            var success = subjectRepo.UpdateSubject(subject, out var errmsg);
            return this.ApiResp(success, errmsg);
        }

        [UserTypeRestricted(UserType.Admin)]
        public IActionResult Delete(int id)
        {
            var success = subjectRepo.DeleteSubject(id, out var errmsg);
            return this.ApiResp(success, errmsg);
        }
    }
}
